package cn.waka.sys.admin.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import cn.waka.sys.admin.object.Result;

public abstract class BaseController {


    public Result login() {
        return error(-403, "沒有登录");
    }

    public Result ok() {
        return new Result();
    }

    public Result ok(Object obj) {
        Result rs = new Result();
        rs.setData(obj);

        return rs;
    }

    public Result ok(Object data, String url) {
        Result rs = new Result();
        rs.setCode(0);
        rs.setUrl(url);
        rs.setData(data);
        return rs;
    }

    public Result error(int code, String msg) {
        Result rs = new Result();
        rs.setCode(code);
        rs.setMsg(msg);
        return rs;
    }

    public Result back(Object obj, int code, String msg) {
        Result rs = new Result();
        rs.setData(obj);
        rs.setCode(code);
        rs.setMsg(msg);
        return rs;
    }
    
    public void write(HttpServletResponse response,String content){
    	response.setCharacterEncoding("UTF-8");
    	try {
			response.getWriter().write(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
}
